package com.xiaoshi.hander;


import com.xiaoshi.enums.JsonReturnEnums;
import com.xiaoshi.utils.JsonResult;
import com.xiaoshi.utils.ResUtil;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * 处理资源服务器异常  没有权限访问该资源
 */
public class ResAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException {


        ResUtil.makeJsonResult(
                response, MediaType.APPLICATION_JSON_UTF8_VALUE,
                JsonResult.fail(JsonReturnEnums.NO_PREM)
        );
    }
}
